package com.atguigu.demo.controller;

import com.atguigu.demo.entity.Schedule;
import com.atguigu.demo.service.api.ScheduleService;
import com.atguigu.demo.utils.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/schedule")
public class ScheduleController {

    @Resource
    private ScheduleService scheduleService;

    @GetMapping()
    public R getAllSchedule() {
        List<Schedule> scheduleList = scheduleService.getAllSchedule();
        return R.ok(scheduleList);
    }

    @DeleteMapping("/{id}")
    public R removeSchedule(@PathVariable("id") Long id) {

        scheduleService.removeSchedule(id);

        return R.ok(null);
    }

    @PostMapping()
    public R saveSchedule(@RequestBody Schedule schedule) {

        scheduleService.saveSchedule(schedule);

        return R.ok(null);
    }

    @PutMapping()
    public R updateSchedule(@RequestBody Schedule schedule) {
        scheduleService.updateSchedule(schedule);
        return R.ok(null);
    }
}
